package spring.framework.core.io;

import cn.hutool.core.lang.Assert;

import java.net.MalformedURLException;

/**
 * @author pengzh
 * @class DefaultResourceLoader
 * @since 2021-09-23
 */
public class DefaultResourceLoader implements ResourceLoader {

    @Override
    public Resource getResource(String location) {
        Assert.notBlank(location, "location can not be blank");
        if (location.startsWith(CLASSPATH_URL_PREFIX)) {
            return new ClassPathResource(location.substring(CLASSPATH_URL_PREFIX.length()));
        } else {
            try {
                return new UrlResource(location);
            } catch (MalformedURLException e) {
                return new FileSystemResource(location);
            }
        }
    }

}
